package ch.jamme.conf.def;

import ch.jamme.conf.*;

/**
 * This is the defualt strategy used to decide how many parallel threads should be used for a given marshall process
 * @author Mario Fusco
 */
public class DefaultMarshallerThreadStrategy implements	MarshallerThreadStrategy {
	
	/**
	 * Returns the number of parallel thread that should be used to marshall the given object.
	 * This default implementation returns the number of available processors on the hosting machine,
	 * so if it has only one processor no parallel thread will be spawn.
	 * @param toBeMarshalled The object that is going to be marshalled
	 * @return The number or threads to use. 
	 */
	public int getMarshallerThreadsNumber(Object toBeMarshalled) {
		return Runtime.getRuntime().availableProcessors();
	}

	/**
	 * Returns the number of parallel thread that should be used to unmarshall the given xml.
	 * This default implementation returns the number of available processors on the hosting machine,
	 * so if it has only one processor no parallel thread will be spawn.
	 * @param xml The xml string that is going to be unmarshalled
	 * @return The number or threads to use.
	 */
	public int getUnmarshallerThreadsNumber(String xml) {
		return Runtime.getRuntime().availableProcessors();
	}
}
